package com.booking.springrestful.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.booking.springrestful.domain.Appointments;
import com.booking.springrestful.domain.Feedback;
import com.booking.springrestful.mapper.AppointmentsMapper;
import com.booking.springrestful.mapper.FeedbackMapper;
import com.booking.springrestful.resp.ResponseResult;
import com.booking.springrestful.utills.StatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

@RestController
@Slf4j
@RequestMapping("/Task")
public class TaskController {

    @Resource
    private AppointmentsMapper appointmentsMapper;

    @Resource
    private FeedbackMapper feedbackMapper;


    // 咨询师检查是否有预约
    @GetMapping("/conCheck")
    private ResponseResult<Boolean> conCheck(Integer counselorid){
        boolean exists = appointmentsMapper.exists(new QueryWrapper<Appointments>().eq("counselorid", counselorid).eq("status", StatusEnum.SCHEDULED));
        return ResponseResult.success(exists);
    }


    // 来访者检查是否已完成
    @GetMapping("/clientCheck")
    private ResponseResult<Boolean> clientCheck(Integer userid){
        List<Appointments> list = appointmentsMapper.selectList(new QueryWrapper<Appointments>().eq("userId", userid).eq("status", StatusEnum.COMPLETED));
        AtomicReference<Boolean> flag= new AtomicReference<>(false);
        list.forEach(item->{
            if (!feedbackMapper.exists(new QueryWrapper<Feedback>().eq("appointmentId",item.getAppointmentid()))){
                flag.set(true);
            }
        });
        return ResponseResult.success(flag.get());
    }



}
